﻿#ifndef RECORDER_H
#define RECORDER_H

#include <QObject>
#include <QFile>
#include <QVector>

/*
    记录器
*/
class Recorder : public QObject
{
    Q_OBJECT
public:
    static Recorder* createRecorder(QObject *parent,
                                    const QString& savedName,
                                    const QString& savedPath="./record");

public:
    explicit Recorder( const QString& name, const QString& path,QObject *parent = nullptr);
    ~Recorder();

    void write(const QString& msg);
    const QVector<QString>& read();
    int count();

    void flush();
    bool open();
    void close();

private:
    QVector<QString> m_records;
    QString m_savedPath;
    QString m_savedName;
    QFile m_file;

    friend Recorder* createRecorder(QObject *parent,const QString& savedName,const QString& savedPath);
};

#endif // RECORDER_H
